package io.iot.pipeline.model;

/**
 * 水表对象
 * @author cary
 */
public class WaterMeter implements IData {
    public enum ValveState {
        ON,OFF,
        UNKNOWN // 异常
    }

    public enum BatteryState {
        UNSTABLE, // 欠压
        STABLE //正常
    }

    public static ValveState parseValveState(byte st) {
        int v = st & 0x3;
        if (v == 0x3) {
            return ValveState.UNKNOWN;
        } else if (v == 0x1) {
            return ValveState.OFF;
        } else if (v == 0x0) {
            return ValveState.ON;
        }
        return null;
    }

    /**
     * 电池电压
     * @param st
     */
    public static BatteryState parseBatteryState(byte st) {
        int v = st & 0x4;
        if (v == 0x4) {
            return BatteryState.UNSTABLE;
        } else if (v == 0x0) {
            return BatteryState.STABLE;
        }
        return null;
    }

    private String id; // 表地址，水表编号
    private String value; // 表读数
    private double tension; // 电压
    private ValveState valveState; // 阀门状态
    private BatteryState batteryState; // 电池电压状态

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getValue() {
        return value;
    }

    public void setValue(String value) {
        this.value = value;
    }

    public double getTension() {
        return tension;
    }

    public void setTension(double tension) {
        this.tension = tension;
    }

    public ValveState getValveState() {
        return valveState;
    }

    public void setValveState(ValveState valveState) {
        this.valveState = valveState;
    }

    public BatteryState getBatteryState() {
        return batteryState;
    }

    public void setBatteryState(BatteryState batteryState) {
        this.batteryState = batteryState;
    }
}
